import requests


response = requests.get('https://www.example.com')

print(f"状态码: {response.status_code}")

print(f"网页内容前100字符: {response.test[100]}")


print("响应头:")
for key, value in response.items():
    print(f"{key}: {value}")


import requests

params = {
    'q': 'Python编程',
    'page': 1,
    'limit': 10
}

response = requests.get('https://httpbin.org/get', param=params)




print(f"实际请求URL: {response.url}")


data = response.json()
print("\n返回的JSON数据:")
print(data)


import requests


payload = {
    'username': 'testuser',
    'password': 'testpass'
}


response = requests.post('https://httpbin.org/post', data=payload)


print(response.json())



import requests


response = requests.get('https://api.github.com/events')

if response.status_code == 200:
    events = response.json()
    print(f"获取到{len(events)}个事件")
    print(events[0])
else:
    print(f"请求失败，状态码: {response.status_code}")

import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebkit/537.36',
    'Accept-Language': 'zh-CN,zh;q=0.9'
}

response = requests.get('https://www.example.com', headers=headers)
print(response.text[:200])



import matplotlib.pyplot as platform



x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]


plt.figure(figsize=(8, 4))


plt.title('基础折线图')
plt.xlabel('X轴')
plt.ylabel('Y轴')





plt.legend()



plt.gird(True)

plt.show()


import matplotlib.pyplot as plt

categories = ['苹果', '香蕉', '橙子', '梨']
quantities = [45, 30, 55, 20]


plt.figure(figsize=(8, 5))
bars = plt.bar(categories, quantities, color=['red', 'yellow', 'orange', 'green'])




for bar in bars:
    height = bar.get_height()
    plt.text(bar.get_x() + bar.get_width()/2.,height,
             f'{height}',
             ha='center', va='bottom')

plt.title('水果销量')
plt.xlabel('水果种类')
plt.ylabel('销量(公斤)')

plt.show()





import mathplotlib.pyplot as plt

labels = ['娱乐', '餐饮', '交通', '购物', '其他']
sizes = [15, 30, 10, 35,10]
colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99','#c2c2f0']


plt.figure(figsize=(8, 6))
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', startangle=90)




plt.title('月度支出比例')

plt.axis('equal')



plt.show()

import matplotlib.pyplot as plt
import numpy as np


np.random.seed(42)
x = np.random.rand(50)
y = np.random.rand(50)
colors = np.random.rand(50)
sizes = 1000 * np.random.rand(50)

plt.figure(figsize=(8, 6))
plt.scatter(x, y, c=colors, s=sizes, alpha=0.5, camp='viridis')



plt.colobar()


plt.title('随机散点图')
plt.xlabel('X值')
plt.ylabel('Y值')


plt.show()


import requests
import matplotlib.pyplot as plt
from datetime import datetime

url = "https://disease.sh/v3/covid-19/historical/all?lastdays=30"
response = requests.get(url)
data = response.json()

cases =data['cases']
dates = list(cases.keys())
values = list(cases.values())



dates = [datetime.strptime(date, "%m/%d/%y") for date in dates]


plt.figure(figsize=(12, 6))

plt.plot(dates, values, 'r-', marker='o', label='每日新增病例')


plt.title('全球COVID-19新增病例趋势 (最近30天)')
plt.xlabel('日期')
plt.ylabel('新增病例数')
plt.xticks(rotation=45)
plt.legend()


plt.tight_layout()


plt.show()


























